import requests
from bs4 import BeautifulSoup

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
}
url = 'http://data.sports.sohu.com/nba/nba_players_rank.php?order_by=points&spm=smpc.fb-nba-home.top-dc.2.1620824904040nf6byr7'
response = requests.get(url=url, headers=header)
response.encoding = 'gbk'
soup = BeautifulSoup(response.text, 'lxml')
list = soup.select('.table01>tr')
fp = open('D:\\qiuyuan.txt', 'w', encoding='gbk')
for i in list:
    name = soup.find('tr', class_='green' + i).a.string
    print(name)
    team = soup.find('td', class_='e3').a.string
    fp.write('name' + name + '' + 'team:' + team + '\n')
